Skip to content

enable react compiler #1321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2025
Merged

enable react compiler #1321

merged 2 commits into from
May 29, 2025

Conversation

bradleyayers
Copy link
Member

@bradleyayers bradleyayers commented May 29, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved modal background transparency for web platforms.
    • Enhanced handling of the global crypto object to avoid overwriting existing implementations.
  • Chores

    • Updated dependency versions for improved compatibility and stability.
    • Refined configuration for Babel, ESLint, and experimental features.
    • Removed obsolete TypeScript type declarations related to ESLint plugins.
  • Refactor

    • Simplified event handling in the quiz progress bar component.
    • Minor code cleanups and directive additions with no user-facing impact.

@Copilot Copilot AI review requested due to automatic review settings May 29, 2025 10:30
@bradleyayers bradleyayers enabled auto-merge May 29, 2025 10:30
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables and configures the new React Compiler across the app, updates related polyfills, removes custom patches, and aligns linting and build configs accordingly.

  • Add React Compiler options to Babel and Expo configs; remove custom React Native Modal patch.
  • Adjust polyfill for crypto, introduce a custom directive in a hook, and clean up event callback usage.
  • Update dependencies (React Native, ESLint plugins) and ESLint config to use latest react-hooks rules.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
projects/app/src/polyfill/crypto.ts Made crypto optional and applied polyfill for getRandomValues
projects/app/src/client/ui/ReplicacheContext.tsx Added "use no memo" React Compiler directive
projects/app/src/client/ui/QuizProgressBar.tsx Removed useEventCallback, inlined handleLayout
projects/app/src/client/ui/PageSheetModal.tsx Replaced backdropColor={false} with transparent={true}
projects/app/package.json Pinned RN version; updated ESLint plugin versions
projects/app/eslint.config.mjs Switched to react-hooks recommended-latest config
projects/app/babel.config.cjs Configured babel-preset-expo for React Compiler options
projects/app/app.config.js Enabled reactCompiler experiment
.yarn/patches/react-native-npm-0.79.2-9db13eddfe.patch Removed custom Modal typing patch
Comments suppressed due to low confidence (1)

projects/app/eslint.config.mjs:35

  • The react-hooks plugin entry was removed from plugins but its recommended-latest config is still applied. Re-add react-hooks under plugins to ensure its rules are actually enabled.
[`react-hooks`]: reactHooksPlugin,

Copy link

coderabbitai bot commented May 29, 2025

Walkthrough

This update modifies configuration files to enable and configure the React Compiler, updates related dependencies, and adjusts ESLint and Babel settings accordingly. It also removes TypeScript type declarations for certain ESLint plugins, updates modal transparency logic, and refines a crypto polyfill assignment to preserve existing implementations.

Changes

Files/Group Change Summary
projects/app/app.config.js, projects/app/package.json Added and then removed "experiments": { "reactCompiler": true } in config; updated dependencies.
projects/app/babel.config.cjs Updated Babel preset to configure React Compiler with strict mode and error threshold.
projects/app/eslint.config.mjs Switched React Hooks plugin config to recommended-latest and removed compatibility wrapper.
projects/app/src/types/eslint-plugin-react-compiler.d.ts, projects/app/src/types/eslint-plugin-react-hooks.d.ts Deleted TypeScript declaration files for ESLint plugin modules.
projects/app/src/client/ui/PageSheetModal.tsx Changed Modal prop from backdropColor={false} to transparent={true} for web.
projects/app/src/client/ui/QuizProgressBar.tsx Removed useEventCallback usage; made handleLayout a plain function.
projects/app/src/client/ui/ReplicacheContext.tsx Added "use no memo"; directive at the start of useRizzleQuery function.
projects/app/src/polyfill/crypto.ts Made global.crypto optional and used nullish assignment for polyfill installation.

Possibly related PRs

  • enable react compiler #1319: Also enables the React Compiler by adding the experimental flag and related Babel configuration, directly aligning with the changes in this PR.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3352a8e and 46ca2a7.

⛔ Files ignored due to path filters (2)
  • .yarn/patches/react-native-npm-0.79.2-9db13eddfe.patch is excluded by !**/.yarn/**
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (10)
  • projects/app/app.config.js (1 hunks)
  • projects/app/babel.config.cjs (1 hunks)
  • projects/app/eslint.config.mjs (1 hunks)
  • projects/app/package.json (2 hunks)
  • projects/app/src/client/ui/PageSheetModal.tsx (1 hunks)
  • projects/app/src/client/ui/QuizProgressBar.tsx (1 hunks)
  • projects/app/src/client/ui/ReplicacheContext.tsx (1 hunks)
  • projects/app/src/polyfill/crypto.ts (1 hunks)
  • projects/app/src/types/eslint-plugin-react-compiler.d.ts (0 hunks)
  • projects/app/src/types/eslint-plugin-react-hooks.d.ts (0 hunks)
💤 Files with no reviewable changes (2)
  • projects/app/src/types/eslint-plugin-react-compiler.d.ts
  • projects/app/src/types/eslint-plugin-react-hooks.d.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: moon-ci (0)
  • GitHub Check: moon-ci (1)
🔇 Additional comments (9)
projects/app/src/client/ui/QuizProgressBar.tsx (1)

84-86: LGTM! Change aligns with React Compiler enablement.

The removal of useEventCallback wrapper is appropriate when React Compiler is enabled, as the compiler should automatically optimize this function to prevent unnecessary re-renders. The core functionality remains unchanged.

projects/app/src/polyfill/crypto.ts (2)

4-4: Good improvement to make the crypto property optional.

Making the crypto property optional in the type declaration accurately reflects that some environments may not have a global crypto object available.


11-11: Excellent use of nullish assignment operator for polyfill.

Using ??= ensures the polyfill is only applied when no existing crypto implementation is present, preventing overwriting of native implementations. This is a best practice for polyfills.

projects/app/src/client/ui/ReplicacheContext.tsx (1)

168-168: Appropriate React Compiler directive for manual memoization control.

The "use no memo"; directive correctly disables automatic memoization for this function, which makes sense given the existing manual memoization logic for stableKey and stableQuery parameters. This prevents conflicts between the React Compiler's automatic optimizations and the intentional manual control needed for the Replicache subscription logic.

projects/app/src/client/ui/PageSheetModal.tsx (1)

166-166: Correct Modal API usage with transparent prop.

Good fix! Changing from backdropColor={false} to transparent={true} uses the correct React Native Modal API. The backdropColor prop doesn't exist on Modal, while transparent is the proper prop to control modal background transparency.

projects/app/app.config.js (1)

153-153:

✅ Verification successful

Correct enablement of React Compiler experimental feature.

Adding reactCompiler: true to the experiments section properly enables the React Compiler feature in Expo. This aligns with the PR objective and should work in conjunction with the Babel configuration updates.

Verify that the Babel configuration has also been updated to support React Compiler:


🏁 Script executed:

#!/bin/bash
# Description: Check if Babel config includes React Compiler setup
# Expected: Babel config should have React Compiler plugin configured

echo "Checking Babel configuration for React Compiler setup..."
fd -e js -e cjs -e mjs babel.config projects/app/ --exec cat {}

Length of output: 687


React Compiler enabled correctly

The reactCompiler: true flag is properly set in the experiments section of projects/app/app.config.js, and the Babel configuration in babel.config.js includes the React Compiler setup:

presets: [
  [
    'babel-preset-expo',
    {
      'react-compiler': {
        compilationMode: 'strict',
        panicThreshold: 'all_errors',
      },
    },
  ],
  'nativewind/babel',
],
plugins: ['babel-plugin-transform-import-meta'],

No further changes are needed.

projects/app/babel.config.cjs (1)

6-18: LGTM! Proper React Compiler configuration.

The React Compiler configuration is well-structured with appropriate settings:

  • compilationMode: "strict" ensures thorough optimization analysis
  • panicThreshold: "all_errors" provides fail-fast behavior for better debugging

This aligns with the PR objective to enable React Compiler.

projects/app/package.json (1)

76-76:

✅ Verification successful

Verify React Native 0.79.2 compatibility with React Compiler.

The version change from a patch to 0.79.2 is significant. Ensure this version is compatible with the React Compiler configuration added in the Babel config.


🌐 Web query:

Is React Native 0.79.2 compatible with React Compiler? What are the minimum React Native version requirements for React Compiler?

💡 Result:

React Native 0.79.2 and React Compiler Compatibility

Compatibility

  • React Compiler is compatible with React version 17 and up, but works best with React 19[1][5][7].
  • For versions of React lower than 19 (i.e., React 17 or 18), you must also install the react-compiler-runtime package and specify the correct target in your compiler configuration[1][5][7].
  • The main requirement from React Native’s side is support for the React version you are using.

React Native Version Requirements

  • The key requirement for React Compiler is not the React Native version directly, but rather the version of React it uses.
  • React Native 0.78 introduced official support for React 19, alongside simplifying the integration process for React Compiler[2][6]. Versions prior to 0.78 typically use React 18 or below.
  • React Native 0.79.2 continues the trend, shipping with React 19 by default[9].

Minimum React Native Version for Out-of-the-Box Support

  • To use React Compiler easily (without extra steps like adding the runtime or complex configurations), your project should be on React Native 0.78 or later with React 19[2][6].
  • If you are on React Native 0.79.2 (which uses React 19 by default), you are fully compatible with React Compiler with the newest and simplest setup[9].
  • For React Native versions between 0.71 and 0.77 (using React 17 or 18), you can still use React Compiler, but you'll need to:
    • Install react-compiler-runtime
    • Set the appropriate target in your Babel config[1][5][7].

Summary Table

React Native Version React Version React Compiler Support Notes
0.78 and up 19 Native/Recommended setup Easiest to use, no extra runtime needed[2][6][9].
0.71 – 0.77 17 or 18 Supported, with extra steps Install react-compiler-runtime, set target[1][5][7].
Below 0.71 ≤16 Not supported React Compiler requires React 17+.

Conclusion

  • React Native 0.79.2 is fully compatible with React Compiler, since it uses React 19 by default.
  • The minimum React Native version for out-of-the-box React Compiler support is 0.78, as this is when React 19 became the default[2][6][9].
  • You can run React Compiler on React Native versions as old as those using React 17, but extra configuration is necessary[1][5][7].

Citations:


React Native 0.79.2 is fully compatible with React Compiler.

React Native 0.79.2 ships with React 19 by default, meeting the out-of-the-box requirements for React Compiler—no additional runtime or target tweaks needed.

projects/app/eslint.config.mjs (1)

61-62:

✅ Verification successful

Verify the 'recommended-latest' configuration exists.

The change from recommended to recommended-latest config aligns with the plugin upgrade, and removing the compat.config wrapper suggests proper flat config support. However, verify that the recommended-latest configuration actually exists in the new plugin version.


🏁 Script executed:

#!/bin/bash
# Description: Verify the available configurations in eslint-plugin-react-hooks
# Expected: Should show available config names including 'recommended-latest'

# Check the package structure to find available configs
fd "package.json" node_modules/eslint-plugin-react-hooks --exec cat {} \; | jq '.exports // .main // "no exports found"'

# Also check if there are any config files
fd -e js -e json . node_modules/eslint-plugin-react-hooks/configs 2>/dev/null || echo "No configs directory found"

Length of output: 380


🌐 Web query:

Does eslint-plugin-react-hooks@6.0.0-rc.1 export a "recommended-latest" configuration in its configs?

💡 Result:

Yes, eslint-plugin-react-hooks@6.0.0-rc.1 does export a "recommended-latest" configuration in its configs. This configuration is specifically designed for users of ESLint 9.0.0 and above who are using the flat config system (eslint.config.js)[2].

The plugin provides different configuration options depending on your ESLint setup:

  1. For ESLint 9.0.0+ using flat config (eslint.config.js):

    • You can use recommended-latest
    • Usage example:
      import reactHooks from 'eslint-plugin-react-hooks';
      export default [
        reactHooks.configs['recommended-latest'],
      ];
  2. For ESLint below 9.0.0 using legacy config (.eslintrc):

    • You should use recommended-legacy
    • Usage example:
      {
        "extends": [
          "plugin:react-hooks/recommended-legacy"
        ]
      }

It's worth noting that while the plugin still supports the plain recommended configuration for backward compatibility, this will change in v6 to alias the flat recommended config[2]. The documentation indicates that these configuration options were introduced to accommodate the transition to ESLint's new flat config format while maintaining support for legacy configurations.

If you're specifically looking to enable the React Compiler rule that was introduced in version 6.0.0-rc.1, you'll need to explicitly add 'react-hooks/react-compiler': 'error' to your ESLint configuration, as this rule is not enabled by default in any of the recommended configurations[4][5].

Citations:


Approve: ‘recommended-latest’ Config Verified

Verified that eslint-plugin-react-hooks@6.0.0-rc.1 exports a recommended-latest configuration for ESLint 9+ flat configs. The change in projects/app/eslint.config.mjs (lines 61–62) is correct as-is.

@bradleyayers bradleyayers added this pull request to the merge queue May 29, 2025
Merged via the queue into main with commit e53a0ce May 29, 2025
8 checks passed
@bradleyayers bradleyayers deleted the dev branch May 29, 2025 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant